clear all;close all;clc


for Hard0_Soft1 = 0:1

    R_control_noise_Cond1 = [38/100 29/100 29/100 26/100 36/100 21/100 31/100 40/100]; % left -60, right +60

    % hard
    R_Processed_noise_Cond1 = [96/100 99/100 98/100 96/100 97/100 96/100 96/100 97/100 ]; % % left -60, right +60

    R_Processed_noise_Cond2 = [91/100 99/100 99/100 95/100 97/100 97/100 98/100 95/100 ]; % % left -15, right +15

    R_Processed_noise_Cond3 = [83/100 82/100 82/100 79/100 85/100 87/100 90/100 86/100]; % % 0, right +5

    R_Processed_noise_Cond4 = [5/100 3/100 0/100 0/100 0/100 0/100 0/100 0/100]; % % Right +85, right +90

    R_Processed_noise_Cond5 = [17/100 3/100 0/100 19/100 9/100 22/100 17/100 18/100]; % % Right +75, right +105

    R_Processed_noise_Cond6 = [72/100 70/100 77/100 66/100 73/100 70/100 63/100 73/100]; % % Back 180, 175


    % ===soft
    R_Soft_control_noise_Cond1 = [38/100 29/100 29/100 26/100 36/100 21/100 31/100 40/100]; % left -60, right +60

    R_Soft_noise_Cond1 = [92/100 90/100 81/100 66/100 71/100 73/100 70/100 79/100]; % % left -60, right +60

    R_Soft_noise_Cond2 = [92/100 91/100 72/100 65/100 78/100 78/100 80/100 75/100]; % % left -15, right +15

    R_Soft_noise_Cond3 = [86/100 85/100 63/100 78/100 85/100 81/100 84/100 32/100]; % % 0, right +5

    R_Soft_noise_Cond4 = [28/100 28/100 24/100 15/100 12/100 20/100 19/100 18/100]; % % Right +85, right +90

    R_Soft_noise_Cond5 = [77/100 66/100 24/100 39/100 36/100 24/100 45/100 30/100]; % % Right +75, right +105

    R_Soft_noise_Cond6 = [85/100 80/100 55/100 46/100 54/100 59/100 56/100 56/100]; % % Back 180, 175

    titles={'A. Front, −60^{o}&+60^{o}','B. Front, −15^{o}&+15^{o}','C. Front, 0^{o}&+5^{o}','D. Side, +85^{o}&+90^{o}','E. Side, +65^{o}&+90^{o}','F. Back, +180^{o}&+175^{o}'};
    figure('position',[100 100 800 450]);
    outP=f_out_plot;
    n=100;
    alpha=0.05;
    for i=1:6
        subplot('position',outP(i,:))
        if Hard0_Soft1==0
            eval(['tem = R_Processed_noise_Cond' num2str(i) ';'])
        elseif Hard0_Soft1==1
            eval(['tem = R_Soft_noise_Cond' num2str(i) ';'])
        end
        pbar = [R_control_noise_Cond1' tem' ].*100;
        bar(pbar)
        mean(tem)

        for icond = 1:2
            for ib = 1:length(pbar)
                CI(icond,ib) = f_confid_I(n,pbar(ib,icond)./100,alpha).*100;
            end
            hold on;
            errorbar((1:8)+0.3.*(icond-1.5),pbar(:,icond),CI(icond,:),'k.');
        end
        xlabel('Sentence Group #');
        ylabel('Percent Correct (%)')
        box off;
        ylim([0 115])
        title(titles{i})

        for igroup = 1:8
            p1=pbar(igroup,1)./100;
            p2=pbar(igroup,2)./100;
            out = f_ztest(p1,p2,100,100);
            if out.p < 0.05/6 & p1<p2
                plot(igroup,max(pbar(igroup,:))+CI(1,igroup)+4,'k*');
            end
        end
        if i==4
            legend('Control','Processed')
            legend boxoff
        end

        if i==2
            if Hard0_Soft1==0
                t=text(5,145,['HRTF-2, Hard Mask, SNR = 0 dB'],'horizontalalignment','center');set(t,'fontsize',12)
            else
                t=text(5,145,['HRTF-2, Soft Mask, SNR = 0 dB'],'horizontalalignment','center');set(t,'fontsize',12)
            end
        end
    end

    if Hard0_Soft1==0
        exportgraphics(gcf, 'BB_S2_Figure9_HardResults.png', 'Resolution', 600,'ContentType', 'vector')
    elseif Hard0_Soft1==1
        exportgraphics(gcf, 'BB_S2_Figure10_SoftResults.png', 'Resolution', 600,'ContentType', 'vector')
    end

end
